Open
Conversation
Member
Author
|
For downstream users: Anyone using $chronos->diff() with type hints will need updates: // If they have:
function process(DateInterval $interval) { ... }
// They need:
function process(DateInterval|ChronosInterval $interval) { ... }
// Or:
$date->diff($other)->toNative() // to get DateInterval CI StatusAll 954 tests pass. The CI failures are due to:
Both issues are expected for this BC break. We will need to decide how to handle:
|
This changes Chronos::diff() and ChronosDate::diff() to return ChronosInterval instead of DateInterval. This provides: - ISO 8601 duration formatting via __toString() - Convenience methods like totalSeconds(), totalDays(), isZero(), isNegative() - Arithmetic methods add(), sub() - toDateString() for strtotime-compatible output - toNative() for backwards compatibility when DateInterval is needed Users who need a DateInterval can call ->toNative() on the result. Also updates fromNow() to return ChronosInterval. Closes #511
Suppress PHP deprecation notice and PHPStan errors for the intentional return type change from DateInterval to ChronosInterval.
15c25e2 to
556c707
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Chronos::diff()andChronosDate::diff()to returnChronosIntervalinstead ofDateIntervalChronosIntervalclass (merged from 3.x branch)fromNow()to returnChronosIntervalThis provides:
__toString()totalSeconds(),totalDays(),isZero(),isNegative()add(),sub()toDateString()for strtotime-compatible outputtoNative()for backwards compatibility when aDateIntervalis neededMigration Path
Users who need a
DateIntervalcan call->toNative()on the result:Note
Good news: No changes required in CakePHP core!
PHPStan reports an error about covariant return types - this is expected for this BC break. The baseline will need to be updated.
Closes #511